package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author mgx
 * @version 1.0
 * @description: TODO
 * @date 2022/10/19 16:15
 */
@RestController
@RequestMapping("/admin/product")
@Api(tags = {"商品基础服务"})
public class BaseManagerController {

    @Autowired
    private ManagerService managerService;

    /**
     * 查询所有的一级分类信息
     */
    @ApiOperation(value = "查询所有的一级分类信息")
    @GetMapping("/getCategory1")
    public Result getCategory1() {
        List<BaseCategory1> list = managerService.getCategory1();
        return Result.ok(list);
    }

    /**
     * 查询一级分类下的二级分类
     */
    @ApiOperation(value = "查询一级分类下的二级分类")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> list = managerService.getCategory2(category1Id);
        return Result.ok(list);
    }

    /**
     * 查询二级分类下的三级分类
     */
    @ApiOperation(value = "查询二级分类下的三级分类")
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> list = managerService.getCategory3(category2Id);
        return Result.ok(list);
    }

    /**
     * 查询分类下的平台属性值
     */
    @ApiOperation(value = "查询分类下的平台属性值")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getAttrInfoList(@PathVariable Long category1Id,
                                  @PathVariable Long category2Id,
                                  @PathVariable Long category3Id) {
        List<BaseAttrInfo> list = managerService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(list);
    }


    /**
     * 保存修改平台属性
     * /admin/product/saveAttrInfo
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        managerService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    //

    /**
     * 修改平台属性回显数据 -- 根据平台属性id查询对应的平台属性值
     * /admin/product/getAttrValueList/{attrId}
     * @param attrId
     * @return
     */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId) {
        BaseAttrInfo baseAttrInfo = managerService.getAttrInfo(attrId);
        List<BaseAttrValue> baseAttrValueList = baseAttrInfo.getAttrValueList();
        return Result.ok(baseAttrValueList);
    }




}
